package com.baizhi.cmfzmanager.service.impl;

import com.baizhi.cmfzmanager.dao.AlbumDao;
import com.baizhi.cmfzmanager.entity.Album;
import com.baizhi.cmfzmanager.service.AlbumService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class AlbumServiceImpl implements AlbumService {

    @Autowired
    private AlbumDao albumDao;
    @Override
    public Map getAlbums(int page, int rows) {
        int start=(page-1)*rows;
        IPage<Album> iPage=new Page<>(start,rows);
        IPage<Album> albumIPage = albumDao.selectPage(iPage, null);
        List<Album> albumList = albumIPage.getRecords();
        long count = albumIPage.getTotal();
        Map map=new HashMap();
        map.put("rows",albumList);
        map.put("total",count);
        return map;
    }

    @Override
    public void update(Album album) {
        albumDao.update(album);
    }

    @Override
    public void add(Album album) {
        albumDao.add(album);
    }

    @Override
    public void delete(int[] ids) {
        albumDao.delete(ids);
    }

    @Override
    public List<Album> getAll() {

        return albumDao.getAll();
    }

    @Override
    public List<Album> getShouyeAlbum() {

        return albumDao.getShouyeAlbum();
    }

    @Override
    public List<Album> getAllAlbum() {

        return albumDao.selectList(null);
    }

    @Override
    public Album getAlbumById(Integer id) {


        return albumDao.getAlbumById(id);
    }
}
